<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="utf-8">
    <title>工资</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../layuimini/css/public.css" media="all">
</head>
<body>
<input type="hidden" name="empid" th:value="${session.loginUser.getEmpId()}">
<table id="table-user" class="layui-table" lay-filter="table-user"></table>
<script type="text/html" id="currentTableBar">
</script>
<script type="text/html" id="toolbar">
    <form class="layui-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" style="width:110px">员工姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="staffname" placeholder="支持模糊查询" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" style="width:110px">工资月份</label>
                <div class="layui-input-inline">
                    <select name="moneydate" class="layui-input"  >
                        <option value="-1">全部月份</option>
                        <option th:each="d:${depar}" th:value="${d.moneydate}" th:text="${d.moneydate}"></option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <button type="button" lay-submit class="layui-btn layui-btn-primary" lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
            </div>
        </div>
    </form>

    <div class="layui-btn-container" shiro:hasPermission="gongzi:jisuan">
        <button th:if="${session.loginUser.getEmpId()==1}" class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 计算工资 </button>
    </div>
</script>
<script src="../layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script th:inline="none">
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var table = layui.table;
        let id=$(":input[name='empid']").val();
        table.render({
            elem: '#table-user',
            url: '/wages/list?id='+id,
            method:'post',
            page: true,
            limits: [10,20,30,50,80,100],
            limit: 10,
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'employee', title: '员工名称',templet:function (d){return d.employee.empName}},
                {field: 'depart', title: '所属部门' ,sort: true,templet:function (d){return d.depart.name}},
                {field: 'moneydate',title: '工资月份', sort: true},
                {field: 'basemoney', title: '基本工资', sort: true},
                {field: 'fullwages', title: '全勤工资', sort: true},
                {field: 'late', title: '迟到扣款', sort: true},
                {field: 'leave',title: '请假扣款', sort: true},
                {field: 'absenteeism',title: '旷工扣款', sort: true},
                {field: 'tax',title: '个税扣款', sort: true},
                {field: 'risk', title: '五险一金', sort: true},
                {field: 'shifamoney', title: '实发工资', sort: true},
                {field: 'establishtime',title: '创建时间', sort: true}
            ]],
            toolbar:"#toolbar",
        });

        table.on('toolbar(table-user)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                layer.confirm('正在计算本月所有人工资详情',function(index){
                    $.post('/wages/insert',function(res){
                        //响应
                        console.log(res);
                        if(res.data==="success"){
                            layer.msg(res.msg);
                            //重新加载表格
                            table.reload('table-user');
                        }
                    });
                    layer.close(index);
                })
            }
        });

        form.on('submit(data-search-btn)',function(data){
            var result=JSON.stringify(data.field);
            console.log(result);
            //执行搜索重载
            table.reload('table-user',{
                page:{
                    curr:1
                },
                where:{
                    staffname:data.field.staffname,
                    moneydate:data.field.moneydate,
                }
            },'data');
            //阻止表单提交
            return false;
        })

    });
</script>
</body>
</html>